package com.gitee.feizns.quickstart.ding.talk.api.top.api.message.corpconversation;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 异步发送 v2
 * @author feizns
 * @since 2025/2/20
 */
public class AsyncSendV2 {

    /**
     * 执行发送消息
     * @param accessToken 访问令牌
     * @param request 请求
     */
    @SneakyThrows
    public static String execute(String accessToken, OapiMessageCorpconversationAsyncsendV2Request request) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
        OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(request, accessToken);
        return Utils.ifErrorThrow(rsp).getBody();
    }

}
